package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Answer;
import cn.wolfcode.trip.base.domain.AskQuestions;
import cn.wolfcode.trip.base.mapper.AnswerMapper;
import cn.wolfcode.trip.base.mapper.AskQuestionsMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IAskQuestionsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AskQuestionsServiceImpl implements IAskQuestionsService{
    @Autowired
    private AskQuestionsMapper questionsMapper;
    @Autowired
    private AnswerMapper answerMapper;

    @Override
    public PageInfo<AskQuestions> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<AskQuestions> askQuestions = questionsMapper.queryForList();
        return new PageInfo<>(askQuestions);
    }

    @Override
    public void save(AskQuestions askQuestions) {
        askQuestions.setCreateTime(new Date());
        questionsMapper.insert(askQuestions);
    }

    @Override
    public void saveAnswer(Answer answer) {
        answer.setCreateTime(new Date());
        answerMapper.insert(answer);
    }

    @Override
    public AskQuestions get(Long quesId) {
        return questionsMapper.selectByPrimaryKey(quesId);
    }

    @Override
    public List<Answer> listAnswer(Long quesId) {

        return answerMapper.listAnswer(quesId);
    }
}
